package cn.edu.scau.cmi.xianjiehua.abstractFactory;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.xianjiehua.abstractFactory.abstractClass.CarDamage;
import cn.edu.scau.cmi.xianjiehua.abstractFactory.abstractClass.Casualties;
import cn.edu.scau.cmi.xianjiehua.abstractFactory.abstractClass.DriverInjured;
import cn.edu.scau.cmi.xianjiehua.abstractFactory.abstractClass.Insurance;
import cn.edu.scau.cmi.xianjiehua.abstractFactory.abstractClass.MultipleAccidents;
import cn.edu.scau.cmi.xianjiehua.abstractFactory.company.PICC;
import cn.edu.scau.cmi.xianjiehua.abstractFactory.company.PingAn;
import cn.edu.scau.cmi.xianjiehua.abstractFactory.factory.CompanyFactory;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;

public class FactoryController implements Initializable {

	@FXML
	private ChoiceBox<String> choice;
	
	@FXML
	private ChoiceBox<String> company;
	
	@FXML
	private Button show;
	
	@FXML
	private TextArea console;

	ObservableList<String> items = FXCollections.observableArrayList(DriverInjured.name,CarDamage.name
			, Casualties.name, MultipleAccidents.name);
	
	ObservableList<String> companys = FXCollections.observableArrayList(PICC.companyName,PingAn.companyName);

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		choice.setItems(items);
		company.setItems(companys);
	}

	public void ButtonAction(ActionEvent event) {
		String enterprise = company.getValue();
		String types = choice.getValue();
		CompanyFactory factory = CompanyFactory.getFactory(enterprise);
		if(factory == null)
			return;
		Insurance insurance = null;
		switch(types) {
		case DriverInjured.name:
			insurance = factory.getDriverInjured();break;
		case CarDamage.name:
			insurance = factory.getCarDamage();break;
		case Casualties.name:
			insurance = factory.getCasualties();break;
		case MultipleAccidents.name:
			insurance = factory.getMulitipleAccidents();break;
		default:
			break;
		}
		if(insurance != null) {
			console.appendText(insurance.getInsurance()+"\n");
		}
		//console.appendText(SimpleFactory.getInstance(select).toString()+"\n");
	}

}
